import { computed } from 'vue';
import { useTranslation } from 'i18next-vue';
import { Message } from '@arco-design/web-vue';

export default function useLocale() {
  const { t, i18next } = useTranslation();
  const currentLocale = computed(() => {
    return i18next.language;
  });
  const changeLocale = (value: string) => {
    if (i18next.language === value) {
      return;
    }
    i18next.changeLanguage(value);
    localStorage.setItem('arco-locale', value);
    Message.success(t('navbar.action.locale'));
  };
  return {
    currentLocale,
    changeLocale,
  };
}
